<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>vue 复习</title>
    <!--Staticfile CDN（国内）-->
    <!--<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>-->
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
    <style>

    </style>
</head>
<body>



<input type="text" name="name">
<input type="text" name="age">
<button onclick="setSession()">set session</button>
<button onclick="getSession()">get session</button>
<div id="showValue"></div>

<script>
    let name = document.querySelector('[name="name"]')
    let age = document.querySelector('[name="age"]')
    let showValue = document.getElementById('showValue')

    function setSession(){

        let user ={}
        user.name = name.value
        user.age =  age.value
        console.log(user)
        sessionStorage.setItem("user", JSON.stringify(user))
        getSession()
    }

    function getSession(){
        let  curUser = sessionStorage.getItem("user");
        if(!curUser)return null;
        curUser  = JSON.parse(curUser)
        showValue.innerHTML = curUser.name + ' ' + curUser.age
    }
    getSession()
</script>
</body>
</html>